<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // class person {
        //     constructor(name, age){
        //         this.name = name
        //         this.age = age
        //     } 
        //     eat = function (params) {
        //         console.log('eat')
        //         return this
        //     }
        // }
        // person.prototype.eat = function (params) {
        //     console.log('eat')
        // }
        // function clone (child,parents){
        //     child.prototype = parents.prototype
        //     child.prototype.constructor = child
        // }
        
        // var student = function (obj) {
        //     this.obj = obj 
        // }
        // student.prototype.play = function (params) {
        //     console.log('play')
        // }

        //  var stu1 = new student('china')
        //  //stu1.prototype = new person('xixi',18)
        //  student.prototype.eat = function () {

        //  }
        //  console.log(stu1)
        // //直接在对象上加方法，constructor会消失，所以要重新指一下
        // student.prototype = {
        //     sleep:function(){
        //         console.log('sleep')
        //     }
        // }
        //student.prototype.constructor = student
         //var stu2 = new student('amer')
         //console.log(stu2)
        // //利用 call 借用构造函数继承
        // function teacher (work) {
        //     this.work = work
        // }
        // class student extends person{
        //     constructor(name,age,obj) {
        //         super(name,age)
        //         this.obj = obj
        //     }
        //     say = function () {
        //         console.log('say')
        //     }
        // }
        
        //clone(student,person)
        // student.prototype.say = function () {
        //     console.log('say')
        // }
        // var stud = new student('kk',[0,1],'hehe')
        // console.log(stud.eat())
        // function xiaochang(work,school){
        //     teacher.call(this,work)
        //     this.school = school
        // }
		// student.prototype = new person()
        // var stu1 = new student('kk',[0,1],'hehe')
        // var stu2 = new student('kkll',[0,1],'jjj')
        // stu1.age.push(9)
        // console.log(stu1)
        // console.log(stu2)
        //xiaochang.prototype = new teacher()
        //xiaochang.prototype.constructor = xiaochang
        // var tea1 = new xiaochang([0],'xiamen')
        // tea1.work.push(9)
        // var tea2 = new xiaochang([9],'fujian')
        // console.log(tea1)
        // console.log(tea2)
        // stu1.name = 'jj'
        // stu1.age.push(7)
        // var stu2 = new student()
        // console.log(stu1)
        // console.log(stu2)
        // console.log(new person())

        // function teacher () {
        //     this.work = [0]
        // }
        // function xiaochang(){
            
        //     this.school = 'school'
        // }
        // xiaochang.prototype = new teacher()
 	   
        // var tea1 = new xiaochang()
        // tea1.work.push(9)
        // var tea2 = new xiaochang()
        // console.log(tea1)
        // console.log(tea2)

        

    // function Person(name,age,sex){
    //     this.name=name;
    //     this.age=age;
    //     this.sex=sex;
    // }
    // Person.prototype.sayHi=function(){
    //     console.log("你好")
     
 
    // function  Student(name,age,sex,score){
    //     //借用构造函数
    //     Person.call(this,name,age,sex)
    //     this.score=score
    // }
    
    //  // 改变了原型指向
    //  Student.prototype=new Person();//不传值
    //  Student.prototype.eat=function(){
    //     console.log("吃东西");
    //  }
    
 
    //  var stu3=new Student("小黑",20,"男","100分")
    //  var stu4=new Student("小hi",9,"男","90分")
    //  console.log(stu3)
    //  console.log(stu4)
    //  console.log(stu3.eat)
    //  console.log(stu3.sayHi)
    // Student.prototype = Person.prototype
    // var stu = new Student("小黑",20,"男","100分")
    // console.log(stu)
        // let parent4 = {
        //     name: "parent4",
        //     friends: ["p1", "p2", "p3"],
        //     getName: function() {
        //         return this.name;
        //     }
        // };
        // function clone(original) {
        // let clone = Object.create(original);
        //     clone.getFriends = function() {
        //         //这里是this指clone  
        //         return this.friends;
        //     };
        //     clone.getName = function() {
        //         //这里是this指clone  
        //         return this.name;
        //     };
        //     return clone;
        // }

        // let person4 = Object.create(parent4);
        // person4.name = "tom";
        // person4.friends.push("jerry");
        // let person5 = Object.create(parent4);
        // person5.friends.push("lucy");
        // console.log(person4.friends);
        // console.log(person5.friends);
        // let person6 = clone(parent4)
        // console.log(person6.getFriends())
        // console.log(person6.getName())

        function person(name, age) {
            this.name = name
            this.age = age
        }
       
        person.prototype.eat = function (params) {
            console.log('eat')
        }
        function clone (child,parents){
            //浅复制父类
            let clone = Object.create(parents); 
            //clone的原型对象指向父类的原型对象，继承父类上的方法
            clone.prototype = parents.prototype
            //子类的原型对象的构造方法指向clone
            child.prototype.constructor = clone
        }
        function clone2(child,parents) {
            //浅复制父类的原型对象
            let clone = Object.create(parents.prototype)
            //clone的构造函数constructor指向子类
            clone.constructor = child
            //子类的prototype指向clone
            child.prototype = clone
        }
        function student (name,age,obj) {
            person.call(this,name,age)
            this.obj = obj
        }
        function student1 (name,age,obj,work) {
            person.call(this,name,age)
            this.obj = obj
            this.work = work
        }
        clone(student,person)
        clone(student1,person)
        student.prototype.say = function () {
            console.log('say')
        }
        student1.prototype.sleep = function (params) {
            console.log('sleep')
        }
        var stud = new student('kk',[0,1],'hehe')
        console.log(stud)
        var studd = new student1('jj',78,'hh','teacher')
        console.log(studd)

    </script>
</body>
</html>
